import os
import imagedeal as ideal
import cv2

from flask import Flask,request, redirect, url_for


UPLOAD_FOLDER = '/data/imgs/resize/'
SRC_FOLDER='/data/imgs/src'
ALLOWED_EXTENSIONS = set(['jpg', 'jpeg', 'gif'])
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = "/data/imgs"
app.config['ALLOWED_EXTENSIONS'] = ALLOWED_EXTENSIONS
def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS

@app.route('/uploadImage', methods=['POST','GET'])
def upload_file():
    result=""
    if request.method == 'POST':
        file = request.files['file']
        resizepath=UPLOAD_FOLDER+file.filename
        srcpath=SRC_FOLDER+file.filename
        ideal.resize(file,resizepath)
        file.save(srcpath)

def getImageTag():
    if request.method=='POST':
        file=request.files['file']
        gray=getGrayImage(file)



def getGrayImage(img):
    if img.ndim == 3:
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    else:
        gray = img